<template>
  <div class="user-wrapper">
    <span class="action">
      <a-icon type="question-circle-o"></a-icon>
    </span>
    <header-notice class="action"/>
    <a-dropdown>
      <span class="action ant-dropdown-link user-dropdown-menu">
        <a-avatar class="avatar" size="small" :src="avatar"/>
        <span>Admin</span>
      </span>
      <a-menu slot="overlay" class="user-dropdown-menu-wrapper">
        <a-menu-item key="0">
          <router-link to="/">
            <a-icon type="user"/>
            <span>个人中心</span>
          </router-link>
        </a-menu-item>
        <a-menu-item key="1">
          <router-link to="/">
            <a-icon type="setting"/>
            <span>账户设置</span>
          </router-link>
        </a-menu-item>
        <a-menu-divider/>
        <a-menu-item key="3">
          <a href="javascript:;" @click="handleLogout">
            <a-icon type="logout"/>
            <span>退出登录</span>
          </a>
        </a-menu-item>
      </a-menu>
    </a-dropdown>
  </div>
</template>

<script>
import HeaderNotice from './HeaderNotice'
import { removeToken } from '@/utils/utils'
const avatar = require('@/assets/img/logo.png')
export default {
  components: {
    HeaderNotice
  },
  data () {
    return {
      avatar: null
    }
  },
  created: function () {
    this.avatar = avatar
  },
  methods: {
    handleLogout () {
      const _this = this
      this.$confirm({
        title: '提示',
        content: '真的要注销登录吗 ?',
        onOk () {
          removeToken()
          _this.$router.push('/login')
        },
        onCancel () {
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
  .user-wrapper {
    float: right;
    height: 100%;
    .action {
      cursor: pointer;
      padding: 0 12px;
      display: inline-block;
      transition: all .3s;
      height: 100%;

      &:hover {
        background: rgba(0, 0, 0, 0.025);
      }
      .avatar {
        margin: 20px 8px 20px 0;
        color: #1890ff;
        background: hsla(0, 0%, 100%, .85);
        vertical-align: middle;
      }
      .icon {
        font-size: 16px;
        padding: 4px;
      }
    }
  }
</style>
